<%@ taglib prefix="s" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 18-10-8
  Time: 下午4:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Input</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $(":input[name=lastName]").change(function () {
                var val = $(this).val();
                val = $.trim(val);
                var $this = $(this);

                if (val !== "") {
                    //把当前节点后面的所有font兄弟节点删除
                    $this.nextAll("font").remove();

                    //发送ajax请求
                    var url = "emp-validLastName";
                    var args = {"lastName": val, "time": new Date()};
                    $.post(url, args, function (data) {
                        //表示可用
                        if (data === "1") {
                            $this.after("&nbsp;<font color='green'>LastName可用</font>")
                        } else if (data === "0") {
                            //不可用
                            $this.after("&nbsp;<font color='red'>LastName不可用</font>")
                        }
                        else {
                            //服务器异常
                            alert("服务器异常");
                        }
                    })
                } else {
                    alert("lastName不能为空");
                    this.focus();
                }
            })
        })
    </script>
</head>
<body>
<h4>Employee Input Page</h4>
<s:form action="emp-save" method="POST">
    <s:if test="id!=null">
        <s:textfield name="lastName" label="lastName" disabled="true"/>
        <s:hidden name="id"/>
        <%--
        <！--通过添加隐藏域的方式把未显示提交的字段值提交到服务器-->
        <s:hidden name="lastName"/>
        <s:hidden name="createTime"/>--%>
    </s:if>
    <s:else>
        <s:textfield name="lastName" label="lastName"/>
    </s:else>

    <s:textfield name="email" label="Email"/>
    <s:textfield name="birth" label="Birth"/>
    <s:select list="#request.departments" listKey="id" listValue="departmentName" name="department.id"
              label="Department"/>
    <s:submit/>
</s:form>
<a href="returnmain.action">Return to main page</a>
</body>
</html>
